import React from 'react';
import Quill from 'quill';
import 'quill/dist/quill.snow.css';


export default class detail extends React.Component {

  constructor(props) {
	  super(props);
	   this.state = {
	  	count:0,
	  	content:"",
	  	value:'<p></p>',
	  };

	  this.editor=null;

	}

	handleChange(content){
        this.setState({
            content: content
        })
    }


    componentDidMount() {
    	const toolbarOptions = [
            ['bold', 'italic', 'underline', 'strike'],        // toggled buttons
            ['blockquote', 'code-block'],
 
            [{ 'header': 1 }, { 'header': 2 }],               // custom button values
            [{ 'list': 'ordered'}, { 'list': 'bullet' }],
            [{ 'script': 'sub'}, { 'script': 'super' }],      // superscript/subscript
            [{ 'indent': '-1'}, { 'indent': '+1' }],          // outdent/indent
            [{ 'direction': 'rtl' }],                         // text direction
 
            [{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
            [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
 
            [{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme
            [{ 'font': [] }],
            [{ 'align': [] }]                                  // remove formatting button
        ];
    	const textbox = this.refs.textarea;
    	const options = {
            debug: 'console',
            modules: {
                toolbar: toolbarOptions
            },
            placeholder: '请输入文本...',
            readOnly: false,
            theme: 'snow'
        };
        const editor =this.editor= new Quill(textbox,options);
		const {value}=this.state;
		if (value) editor.clipboard.dangerouslyPasteHTML(value);
		editor.on('text-change', this.handleChange.bind(this));
    }

    handleChange () {
        let {value}=this.state;
        value = this.editor.root.innerHTML;
        this.setState({value});
        this.props.count(value);
    }
  render() {
    return (
		<div ref="textarea" style={{minHeight:'120px',maxHeight:'500px',overflow:'auto'}} ></div>
    );
  }
}